import { ref, computed, type Ref } from 'vue'
import { defineStore } from 'pinia'
import type { MenuTypes } from '@/resources/interface/menu/MenuTypes.ts'
import type { UserLoginVOType } from '@/resources/interface/user/UserTypes.ts'
import { UserParams } from '@/resources/parameters/user/UserParameters.ts'

export const useUserStore = defineStore(
  'user',
  () => {
    const user = ref<UserLoginVOType>(UserParams.loginVO)
    const setUser = (value: UserLoginVOType) => {
      user.value = value
    }
    const getUser = () => {
      return user.value
    }
    const hasUser = () => {
      return user.value != UserParams.loginVO
    }
    const clearUser = () => {
      user.value = UserParams.loginVO
    }
    return { user, setUser, getUser, hasUser, clearUser }
  },
  {
    persist: true,
  },
)
export const useTokenStore = defineStore(
  'token',
  () => {
    const token = ref('')
    const setToken = (value: string) => {
      token.value = value
    }
    const getToken = () => {
      return token.value
    }
    const hasToken = () => {
      return token.value != ''
    }
    const clearToken = () => {
      token.value = ''
    }
    return { token, setToken, getToken, hasToken, clearToken }
  },
  {
    persist: true,
  },
)

export const useMenuListStore = defineStore(
  'menuList',
  () => {
    const menuList: Ref<MenuTypes[]> = ref([])
    const saveMenuList = (value: MenuTypes[]) => {
      menuList.value = value
    }
    const clearMenuList = () => {
      menuList.value = []
    }
    return { menuList, saveMenuList, clearMenuList }
  },
  {
    persist: true,
  },
)
